package ink.lovejinhu.leetcode;

/**
 * @author jinhu
 * created 2021-07-16 13:47
 */
public class Solution_0434 {
    /**
     * 字符串中单词的个数
     *
     * @param s
     * @return
     */
    public int countSegments(String s) {
        s += ' ';
        int cnt = 0;
        for (int i = 0; i < s.length() - 1; i++) {
            if (s.charAt(i) != ' ' && s.charAt(i + 1) == ' ') {
                cnt++;
            }
        }
        return cnt;
    }
}
